Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unit Test improvements] Use getMockBuilder rather than getMock directly #12990

Merged
merged 94 commits into from
Dec 11, 2016

Conversation

photodude
Copy link
Contributor

@photodude photodude commented Nov 23, 2016

Pull Request for Issue getMock was used directly.

Summary of Changes

Use getMockBuilder rather than getMock directly
This is needed to avoid situations that would cause PHP Fatal error: Call to protected method PHPUnit_Framework_TestCase::getMock() on newer versions of phpunit

Also fixes a missing method in the application cms mock needed for phpunit 5.6 compatibility, and fixes a mockdatabase issue in the JInstallerAdapter tests on hhvm

Testing Instructions

Merge by code review, Travis tests pass

Documentation Changes Required

none

@mbabker
Copy link
Contributor

mbabker commented Nov 23, 2016

I was about to say I thought some of these were changed in the 4.0 branch, but looking it up it looks like what was changed actually dealt with some of the classes becoming abstract versus concrete (so using the getMockForAbstractClass() method.

Looks fine to me.

@photodude
Copy link
Contributor Author

photodude commented Nov 23, 2016

@mbabker The next big thing to fix in the unit tests after this is merged are the Assert Tags

PHPUnit_Framework_Assert::assertTag is deprecated: 59x
    10x in JFormFieldRadioTest::testGetInput
    6x in JFormTest::testGetInput
    3x in JFormFieldCheckboxesTest::testGetInputValueArrayNoChecked
    3x in JFormFieldCheckboxesTest::testGetInputValueNoChecked
    3x in JFormFieldCheckboxesTest::testGetInputNoValueNoChecked
    3x in JFormFieldCheckboxesTest::testGetInputNoValueOneChecked
    3x in JFormFieldCheckboxesTest::testGetInputValuesNoChecked
    3x in JFormFieldCheckboxesTest::testGetInputValueChecked
    3x in JFormFieldCheckboxesTest::testGetInputNoValueTwoChecked
    2x in JFormFieldTest::testSetup
    2x in JFormFieldTest::testGetLabel
    2x in JHtmlBatchTest::testItem
    2x in JHtmlBatchTest::testUser
    2x in JHtmlBatchTest::testAccess
    2x in JHtmlListTest::testUsers
    2x in JHtmlBatchTest::testLanguage
    1x in JFormFieldHiddenTest::testGetInput
    1x in JHtmlBootstrapTest::testRenderModal
    1x in JHtmlBootstrapTest::testStartAccordion
    1x in JHtmlBootstrapTest::testAddTab
    1x in JFormTest::testGetLabel
    1x in JHtmlBootstrapTest::testStartTabSet
    1x in JHtmlBootstrapTest::testaddSlide
    1x in JHtmlListTest::testPositions

@photodude
Copy link
Contributor Author

Ugh, it appears there are nearly 2000 more places where we need to Use getMockBuilder rather than getMock directly

@mbabker
Copy link
Contributor

mbabker commented Nov 23, 2016

Do it on the 4.0 branch and that should be cut in half easily 😉

Fixes 10 hhvm failures that have one of the following messages
```php
UnexpectedValueException: No columns found for #__extensions table

Expectation failed for method name is equal to <string:parseSchemaUpdates> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.
```
@photodude
Copy link
Contributor Author

@mbabker I decided that I might as well just fix the test with hhvm failures in this PR.

@rdeutz rdeutz self-assigned this Nov 28, 2016
@rdeutz
Copy link
Contributor

rdeutz commented Nov 28, 2016

hope to find time to test it, thanks for the work on this

@photodude
Copy link
Contributor Author

@rdeutz you are welcome. I hope we can get this merged soon.

@rdeutz rdeutz added this to the Joomla 3.7.0 milestone Dec 5, 2016
@photodude
Copy link
Contributor Author

Once this PR is merged we can also close issue #10220

@photodude
Copy link
Contributor Author

After this PR is merged we can consider moving HHVM out of the allowed failures on Travis.

@@ -184,7 +183,7 @@ public function testProcessElementWithEntry()
public function testFetchNamespace()
{
// Set a mock namespace into the namespaces for the parser object.
$mock = $this->getMock('JFeedParserNamespace');
$mock = $this->getMockBuilder('JFeedParserNamespace')->getMock();;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: ;;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that, I have fixed this.

)
);
JFactory::$application = $this->getMockBuilder('JApplication')
->setMethods(array('get', 'getCfg', 'getRouter',))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style ',)'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what your referencing here arrays should end with a comma

Copy link
Contributor

@csthomas csthomas Dec 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For one line array I suggest to not use comma before ')'
array('get', 'getCfg', 'getRouter' =>,<= )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whey they're multiline arrays you should end it with a comma. A single line array like this one, the trailing comma can be left off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For single line array, can or should leave off the trailing comma? I generally take the stance of always including the trailing comma.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's set in stone anywhere, but the general convention across the board (not just here in Joomla land) is single line arrays don't have a trailing comma while multiline arrays do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it helps speed getting this approved and merged.... I have made the changes

)
);
JFactory::$application = $this->getMockBuilder('JApplication')
->setMethods(array('get', 'getCfg', 'getRouter',))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style ',)'

$mockTableExtension = $this->getMock('JTableExtension', array('find', 'load'), array($this->getMockDatabase()));
$mockTableExtension = $this->getMockBuilder('JTableExtension')
->setMethods(array('find', 'load'))
->setConstructorArgs(array(self::$driver))
Copy link
Contributor

@csthomas csthomas Dec 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which way is correct? Use self:driver or $this->getMockDatabase() as below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some issue with this specific test using $this->getMockDatabase() on HHVM that causes 9 failures and 1 error. Using self:driver in this one test resolves all of those issues.

Copy link
Contributor

@csthomas csthomas Dec 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably is not related to current PR.

If I correctly understand $this->getMockDatabase() simulates a connection to the database.
Then using self::$driver is correct.

It should be used too in method below testCheckExistingExtensionForExtensionThatDoesNotExist.

Notice: Parent class TestCaseDatabase always create a real connection to sqlite in self::$driver. Probably we do not need to use a mock database at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree "probably is not related to current PR"

@photodude
Copy link
Contributor Author

@csthomas With the requested changes implemented, would you mark your code review successful?

@csthomas
Copy link
Contributor

Yes. I wanted to check success it yesterday but I have tried to understand the way how does $this->getMockDatabase() work on php versions but not for hhvm. There are other tests with mock database and passed which I do not understand for now.

This is not directly related to this PR.

@csthomas
Copy link
Contributor

I have tested this item ✅ successfully on b5d6a6d

Code review.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12990.

@rdeutz rdeutz merged commit d9e1f90 into joomla:staging Dec 11, 2016
@rdeutz
Copy link
Contributor

rdeutz commented Dec 11, 2016

@photodude Thanks, this was a really big PR and a lot of work. Could you make smaller parts in the future, please, then there is not so much danger that we run into conflicts :-)

@photodude photodude deleted the patch-14 branch December 11, 2016 16:56
@photodude
Copy link
Contributor Author

@rdeutz, you are welcome, thank you for merging. I do generally try to avoid such large PRs. Like the code style PRs I've done, I've keep those to single components. I agree the large PRs are difficult to review and cause other issues like merge conflicts across other open PRs; and that should generally be avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants